<!DOCTYPE html>
<html lang="ch" style="height: 100%">
<head>
    <meta charset="utf-8">
</head>
<body style="height: 90%">
<div id="container" style="height: 90%"></div>


<script type="text/javascript" src="echarts.min.js"></script>
<script type="text/javascript">
    var chartDom = document.getElementById('container');
    var myChart = echarts.init(chartDom);
    myChart.getZr().on('click', function(params) {
      const pointInPixel = [params.offsetX, params.offsetY]
      const { target, topTarget } = params
      if (target?.z === 2 || topTarget?.z === 2) {
        const axs = target? target.seriesIndex: topTarget.parent?.parent?.__ecComponentInfo?.index
        console.log(axs)
      }
    })
    myChart.getZr().on('mousemove', function(params) {
      const { topTarget } = params
      if (topTarget?.z === 2) {
        myChart.getZr().setCursorStyle('pointer')
      }
    })

    function loadEcharts(dataArray){
        var array = JSON.parse(dataArray);
        var option;
        option = {
              grid: { x: 50, y: 25, x2: 30, y2: 20 },
              xAxis: {
                type: 'category',
                data: array.xLabel,
              },
              yAxis: {
                 axisLabel:{
                    showMaxLabel: false,
                    formatter:  function(value){
                        if(value == 1){
                            return "18.5";
                        }else if(value == 2){
                            return "23.9";
                        }else if(value == 3){
                            return "27.9";
                        }else {
                            return "";
                        }
                    },
                 },
                type: 'value',
              },
              series: [
                {
                  data: [1.0,2.0,3.0,4.0],
                  type: 'bar',
                  barWidth: '30%',
                  itemStyle: {
                    normal: {
                      color: function(params){
                        if(params.value === array.yLabel[0]){
                            return new echarts.graphic.LinearGradient(0,0, 0,1, [{ offset: 0,color: 'rgba(77,157,180,1)' },{ offset: 1,color: 'rgba(77,157,180,0)'} ],false )
                        }else{
                            return new echarts.graphic.LinearGradient(0,0, 0,1, [{ offset: 0,color: 'rgba(255,255,255,0.38)' },{ offset: 1,color: 'rgba(77,157,180,0)'} ],false )
                        }
                      },
                      barBorderRadius: [50, 50, 0, 0],
                      //shadowColor: 'rgba(0,160,221,1)',
                      //shadowBlur: 4
                    }
                  }
                }
              ]
            };

        option && myChart.setOption(option);
    }

  </script>
</body>
</html>